package com.yuanqiworld.vw.web;

import com.yuanqiworld.vw.domain.Transform;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.roo.addon.web.mvc.controller.converter.RooConversionService;

/**
 * A central place to register application converters and formatters. 
 */
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

	@Override
	protected void installFormatters(FormatterRegistry registry) {
		super.installFormatters(registry);
		// Register application converters and formatters
        registry.addConverter(getTransformToStringConverter());
	}

    private Converter<Transform, String> getTransformToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<Transform, String>() {
            public String convert(Transform transform) {
                return new StringBuilder().append(transform.getPosition()).append(' ').append(transform.getRotation()).append(' ').append(transform.getScale()).toString();
            }
        };
    }
}
